import * as React from 'react';
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import VConsole from '@kafudev/react-native-vconsole'

import Login from '../../Page/base/security/views/Login';
import User from '../../Page/base/security/views/User';
import Home from '../../Page/base/Home';
import Menu from '../../Page/base/Menu';

import Drawer from './Drawer';
import ForgotPassword from '../../Page/base/security/views/ForgotPassword';
import ChangePassword from '../../Page/base/security/views/ChangePassword';

import Route from './Route';

const RootStack = createNativeStackNavigator();

const Stack = () => {
  let pages = showAblePages();
  return (
    <NavigationContainer>
      <RootStack.Navigator initialRouteName={'Login'}>
        <RootStack.Screen
          name="Login"
          component={Login}
          options={{headerShown: false}}
        />
        <RootStack.Screen
          name="User"
          component={User}
          options={{title: '用户信息'}}
        />
        <RootStack.Screen
          name="Home"
          component={Home}
          options={{headerShown: false}}
        />
        <RootStack.Screen
          name="Menu"
          component={Menu}
          options={{headerShown: false}}
        />
        <RootStack.Screen
          name="Drawer"
          component={Drawer}
          options={{headerShown: false}}
        />
        <RootStack.Screen
            name="ChangePassword"
            component={ChangePassword}
            options={{title: '密码修改'}}
        />
        <RootStack.Screen
          name="ForgotPassword"
          component={ForgotPassword}
          options={{title: '忘记密码'}}
        />
        {pages.map(page => (
          <RootStack.Screen
            key={page.name}
            name={page.name}
            component={page.component}
            options={{title: page.title}}
          />
        ))}
      </RootStack.Navigator>
      {/*调试工具*/}
      <VConsole
          console={__DEV__ ? !console.time : true}
          showBtn={__DEV__ && config.ENABLE_DEBUG === "true"}
      />
    </NavigationContainer>
  );
};

const showAblePages = () => {
  return Route.filter(item => !item.ignore);
};

export default Stack;
